package day08.synch;

/**
 * Package: day08.synch
 * Description： TODO
 * Author: Forest
 * Date: Created in 2021/3/30 10:37
 * Version: 0.0.1
 * Modified By: duforest
 */
public class SyncTest2 {


    public static void main(String[] args) {

        SyncTest2 syncTest2 = new SyncTest2();
        SyncTest2 syncTest23 = new SyncTest2();

        Thread thread = new Thread(new Runnable() {
            @Override
            public void run() {
                syncTest23.foo();
            }
        });

        thread.start();

        Thread thread2 = new Thread(new Runnable() {
            @Override
            public void run() {
                syncTest2.foo();
            }
        });

        thread2.start();
    }

    static int num = 10;

    private static synchronized void foo() {
        while (num > 0) {
            num--;
            System.out.println(num + "," + Thread.currentThread().getName());
        }
    }

}
